//战斗动作管理
window._FAM = {

    ATYPE_ATTACK:'attack',//普通攻击
    ATYPE_ATTACK2:'attack2',//连击
    ATYPE_ATTACK3:'attack3',//协战
    ATYPE_ATTACK4:'attack4',//反击
    ATYPE_SKILL:'skill',//技能
    ATYPE_SKILL2:'skill2',//技能连击
    ATYPE_SKILL3:'skill3',//技能协战
    ATYPE_SKILL4:'skill4',//技能反击
    ATYPE_ITEM:'item',//道具
    ATYPE_RUN:'run',//逃跑
    ATYPE_WAIT:'wait',//待机

    ATYPE_LABEL_MAP:{

        'attack2':'连击',
        'attack3':'协战',
        'attack4':'反击',

        'skill2':'连珠',
        'skill3':'共鸣',
        'skill4':'学舌',
    },

    moveFront:cc.moveTo(0.1,150,0),

    moveBack:cc.moveTo(0.1,20,0),

    moveWait:cc.delayTime(0.2),

    runWait:cc.delayTime(1),

    actionWait:cc.delayTime(1),

    //创建法术连击
    createLianjiActionOfSkill:function(actionParam){
        var player = actionParam.player;
        var targetArr = actionParam.targetArr;
        var skillName = actionParam.skillName;

        if(skillName=="漫天花雨"){
            return;
        }

        if(_FAM.canLianZhu(player))
        _FIGHT.actionQueueLianji.push({player:player,
                                       targetArr:targetArr,
                                       type:_FAM.ATYPE_SKILL2,
                                       skillName:skillName});
        
    },

    //创建法术反击动作
    createFanjiActionOfSkill:function(actionParam){
        var player = actionParam.player;
        var targetArr = actionParam.targetArr;
        var skillName = actionParam.skillName;

        //if(skillName=="漫天花雨"||skillName=="自爆"||skillName=="变鸡术"||skillName=="召唤对面"||skillName=="天地同寿"){
        //    return;
        //}

        if(_SKILL[skillName]&&_SKILL[skillName].nofanji){
            return;
        }

        for(var i=0;i<targetArr.length;i++){
            var target = targetArr[i];
            if(_FAM.canXueshe(target)){
                var xueshetarget;
                if(_SKILL[skillName].single){
                    xueshetarget=[player];
                }else{
                    xueshetarget=_FIGHT.getArmyTeamByPlayer(player,false);
                }
                _FIGHT.actionQueueFanji.push({player:target,
                    targetArr:xueshetarget,
                    type:_FAM.ATYPE_SKILL4,
                    skillName:skillName});
            }
        }
    },

    //创建法术协战动作
    createXiezhanActionOfSkill:function(actionParam){
        var player = actionParam.player;
        var targetArr = actionParam.targetArr;
        var skillName = actionParam.skillName;

        if(skillName=="漫天花雨"){
            return;
        }

        var friendTeam = _FIGHT.getteamPlayerArrByPlayer(player,true);
        for(var i=0;i<friendTeam.length;i++){
            if(_FAM.canGongming(friendTeam[i],skillName)){
                //console.log('法术共鸣',friendTeam[i],skillName);
                _FIGHT.actionQueueXiezhan.push({player:friendTeam[i],
                                               targetArr:targetArr,
                                               type:_FAM.ATYPE_SKILL3,
                                               skillName:skillName});
            }
        }
    },


    //创建物理连击动作
    createLianjiAction:function(actionParam){
        var player = actionParam.player;
        var target = actionParam.target;
        var ljnmb = _FAM.getLianhuan(actionParam.player);
        for(var i=0;i<ljnmb;i++){
            _FIGHT.actionQueueLianji.push({player:player,target:target,type:_FAM.ATYPE_ATTACK2});
        }
    },

    //创建物理反击动作
    createFanjiAction:function(actionParam){
        var player = actionParam.player;
        var target = actionParam.target;
        if(_FAM.canFanji(target)){
            _FIGHT.actionQueueFanji.push({player:target,target:player,type:_FAM.ATYPE_ATTACK4});
        }
    },

    //创建物理协战动作
    createXiezhanAction:function(actionParam){
        var player = actionParam.player;
        var target = actionParam.target;
        var friendTeam = _FIGHT.getteamPlayerArrByPlayer(player,true);
        for(var i=0;i<friendTeam.length;i++){
            if(_FAM.canXiezhan(friendTeam[i])){
                _FIGHT.actionQueueXiezhan.push({player:friendTeam[i],target:target,type:_FAM.ATYPE_ATTACK3});
            }
        }
    },

    //角色行动前衍生动作
    /*
        {
            player:this.doactionPlayer,
            target:target,
            type:'attack'
        }
    */
    createOtherAction:function(actionParam){

        //console.log('判断衍生动作:',actionParam);

        if(actionParam){

            var player = actionParam.player;
            var target = actionParam.target;

            if(actionParam.type==_FAM.ATYPE_ATTACK){//普通攻击衍生 连击 反击 协战

                _FAM.createLianjiAction(actionParam);
                _FAM.createFanjiAction(actionParam);
                _FAM.createXiezhanAction(actionParam);

            }else if(actionParam.type==_FAM.ATYPE_ATTACK4){//反击衍生 连环

                _FAM.createLianjiAction(actionParam);

            }else if(actionParam.type==_FAM.ATYPE_ATTACK3){//协战衍生 反击

                _FAM.createLianjiAction(actionParam);
                _FAM.createFanjiAction(actionParam);

            }else if(actionParam.type==_FAM.ATYPE_SKILL){//技能衍生技能 技能连击  技能协战 技能反击

                _FAM.createLianjiActionOfSkill(actionParam);
                _FAM.createFanjiActionOfSkill(actionParam);
                _FAM.createXiezhanActionOfSkill(actionParam);

            }else if(actionParam.type==_FAM.ATYPE_SKILL4){//技能反击衍生 技能连击

                _FAM.createLianjiActionOfSkill(actionParam);

            }else if(actionParam.type==_FAM.ATYPE_SKILL3){//技能协战衍生 技能反击

                _FAM.createLianjiActionOfSkill(actionParam);
                _FAM.createFanjiActionOfSkill(actionParam);

            }

        }

        //console.log('连击：',_FIGHT.actionQueueLianji,'反击：',_FIGHT.actionQueueFanji,
        //         '协战：',_FIGHT.actionQueueXiezhan);
    },

    //判断是否能法术连击
    canLianZhu:function(player){
        return _ROLEDATA.getRealAttr(player,'lianjiSkill')>0;
    },

    //判断是否能法术共鸣
    canGongming:function(player,skillName){

        return  _ROLEDATA.getRealAttr(player,'xiezhanSkill')>0
                &&player.skill
                &&player.skill.indexOf(skillName)!=-1;
                
    },

    //判断是否能法术反击
    canXueshe:function(player){
        return _ROLEDATA.getRealAttr(player,'fanjiSkill')>0;
    },

    //判断是否能物理协战
    canXiezhan:function(player){
        return _ROLEDATA.getRealAttr(player,'xiezhan')>0;
    },

    //判断是否能物理反击
    canFanji:function(player){
        return _ROLEDATA.getRealAttr(player,'fanji')>0;
    },

    //判断是否能物理连击
    getLianhuan:function(player){
        return _ROLEDATA.getRealAttr(player,'lianji');
    },
    
    getActionWait:function(actionParam){

        var type = actionParam.type;
        var skillName = null;

        if(//普通攻击动作
        type==_FAM.ATYPE_ATTACK
        ||type==_FAM.ATYPE_ATTACK2
        ||type==_FAM.ATYPE_ATTACK3
        ||type==_FAM.ATYPE_ATTACK4
        ){
            skillName='putong';
        }else if(//技能动作
        type==_FAM.ATYPE_SKILL
        ||type==_FAM.ATYPE_SKILL2
        ||type==_FAM.ATYPE_SKILL3
        ||type==_FAM.ATYPE_SKILL4
        ){
            if(_SKILL[actionParam.skillName]){
                skillName = _SKILL[actionParam.skillName].ani;
            }
        }

        var waitTime = _GRM.getAniPlayTime(skillName);

        //console.log('动画名称和等待时间:',skillName,waitTime);

        return cc.delayTime(waitTime);
    },

    getActionArrBeforeRealAction:function(actionParam){

        var doactionPlayer = actionParam.player;
        var doactionPlayerNode = _FIGHT.getPlayerNodeByPlayer(doactionPlayer);
        var doactionPlayerData = _ROLEDATA.getRoleDataOfPlayer(doactionPlayer);

        var actionArr = [];

        //回血动作
        if(doactionPlayerData.hpRecovery){
            actionArr.push(_FAM.calPlayerHp(doactionPlayerNode,doactionPlayer,doactionPlayerData));
            actionArr.push(cc.delayTime(1));
        }

        //回蓝动作
        if(doactionPlayerData.MagicRecovery){
            actionArr.push(_FAM.calPlayerMagic(doactionPlayerNode,doactionPlayer,doactionPlayerData));
            actionArr.push(cc.delayTime(1));
        }

        //中毒动作
        if(RSH.hasDu(doactionPlayer.statusArr)){
            actionArr.push(_FAM.calPlayerDu(doactionPlayerNode,doactionPlayer,doactionPlayerData));
            actionArr.push(cc.delayTime(1));
        }

        return actionArr;
    },


    reCreateActionParam:function(actionParam){
        if(actionParam.type==_FAM.ATYPE_ATTACK){
            actionParam.target = _FIGHT.getCfByplayer(actionParam.target)
        }
    },

    getActionArr:function(actionParam){

        //判断嘲讽
        _FAM.reCreateActionParam(actionParam);

        

        var doactionPlayer = actionParam.player;
        var doactionPlayerNode = _FIGHT.getPlayerNodeByPlayer(doactionPlayer);
        //console.log('行动节点:',actionParam,doactionPlayerNode);

        var actionArr = [];

        //判断player是否能行动
        if(!_FIGHT.checkPlayerCanDoAction(doactionPlayer)){
            //doactionPlayer.eg=0;
            _FIGHT.fightLog(doactionPlayer.name+"无法行动");
            actionArr.push(_FAM.moveWait);
            actionArr.push(_FAM.refreshActionPlayer(doactionPlayerNode,doactionPlayer));
            actionArr.push(_FAM.goon());
            return actionArr;
        }else{
            //创建衍生动作
            _FAM.createOtherAction(actionParam);
        }

        if(actionParam.type!=_FAM.ATYPE_RUN&&actionParam.type!=_FAM.ATYPE_WAIT){
            actionArr.push(_FAM.moveToFight(doactionPlayerNode));
            actionArr.push(_FAM.moveWait);
            actionArr.push(cc.callFunc(_FAM.doOnceActionFunc,doactionPlayerNode,actionParam));
            actionArr.push(_FAM.getActionWait(actionParam));
            actionArr.push(_FAM.refreshActionPlayer(doactionPlayerNode,doactionPlayer));
            actionArr.push(_FAM.moveToBack(doactionPlayerNode));
            actionArr.push(_FAM.moveWait);
            actionArr.push(_FAM.goon());
        }else if(actionParam.type==_FAM.ATYPE_RUN){

            if(_MFD.isCanRun(actionParam.player)){

                actionArr.push(_FAM.setRundir(doactionPlayerNode,doactionPlayer));
                actionArr.push(_FAM.runWait);
                actionArr.push(_FAM.runOut(doactionPlayerNode,doactionPlayer));
                actionArr.push(_FAM.runWait);
                actionArr.push(_FAM.runSuccess());

            }else{

                actionArr.push(_FAM.setRundir(doactionPlayerNode,doactionPlayer));
                actionArr.push(_FAM.runWait);
                actionArr.push(_FAM.setBackDir(doactionPlayerNode,doactionPlayer));
                actionArr.push(_FAM.refreshActionPlayer(doactionPlayerNode,doactionPlayer));
                actionArr.push(_FAM.moveToBack(doactionPlayerNode));
                actionArr.push(_FAM.moveWait);
                actionArr.push(_FAM.goon());

            }

        }else {

            actionArr.push(_FAM.moveToFight(doactionPlayerNode));
            actionArr.push(_FAM.moveWait);
            actionArr.push(_FAM.waitCmd());

        }
        return actionArr;
    },

    setRundirFunc:function(playerNode,player){
        _FIGHT.fightLog(player.name+'开始逃跑');
        _MFN.refreshPlayerInfo(this,player);
        this.getChildByName('role').setScale(2,2);
        this.getChildByName('info').active = false;
    },

    setBackDirFunc:function(playerNode,player){
        _FIGHT.fightLogAdd(player.name+'逃跑失败');
        this.getChildByName('role').setScale(-2,2);
        this.getChildByName('info').active = true;
    },

    runOutFunc:function(playerNode,player){

        var team = _FIGHT.getArmyTeamByPlayer(player,false);
        for(var i=0;i<team.length;i++){

           var teamNode =  _FIGHT.getPlayerNodeByPlayer(team[i]);
           teamNode.getChildByName('role').setScale(2,2);
           teamNode.getChildByName('info').active = false;
           teamNode.getChildByName('role').runAction(cc.moveBy(0.8,-999,0));
        }

    },

    runOut:function(playerNode,player){
        return cc.callFunc(_FAM.runOutFunc,playerNode,player);
    },

    setRundir:function(playerNode,player){
        return cc.callFunc(_FAM.setRundirFunc,playerNode,player);
    },

    setBackDir:function(playerNode,player){
        return cc.callFunc(_FAM.setBackDirFunc,playerNode,player);
    },

    moveToBack:function(doactionPlayerNode){
        return cc.callFunc(_FAM.moveBackFunc,doactionPlayerNode);
    },

    moveToFight:function(doactionPlayerNode){
        return cc.callFunc(_FAM.moveToFightFunc,doactionPlayerNode);
    },

    moveToFightFunc:function(){
        this.getChildByName('role').runAction(_FAM.moveFront);
    },

    moveBackFunc:function(){
        this.getChildByName('role').runAction(_FAM.moveBack);
    },

    refreshActionPlayer:function(doactionPlayerNode,doactionPlayer){
        return cc.callFunc(_FAM.refreshActionPlayerFunc,doactionPlayerNode,doactionPlayer)
    },

    refreshActionPlayerFunc:function(target,param){
        if(param&&param.statusArr&&param.statusArr.length>0)
            RSH.statusReduce(param.statusArr);
        _MFN.refreshPlayerNode(this,param);
    },

    calPlayerHp:function(doactionPlayerNode,doactionPlayer,doactionPlayerData){
        return cc.callFunc(_FAM.calPlayerHpFunc,doactionPlayerNode,{player:doactionPlayer,data:doactionPlayerData});
    },

    calPlayerHpFunc:function(target,param){
        var player = param.player;
        var playerData = param.data;
        var hp = Math.floor(playerData.maxHp*(playerData.hpRecovery/100));
        var realhp  = _MFD.addHp(player,hp);
        _GRM.addHitOnPlayerNode('hong',realhp,this,player.isplayer,{ismsgmove:1});
        _MFN.refreshPlayerNode(this,player);
    },

    calPlayerMagic:function(doactionPlayerNode,doactionPlayer,doactionPlayerData){
        return cc.callFunc(_FAM.calPlayerMagicFunc,doactionPlayerNode,{player:doactionPlayer,data:doactionPlayerData});
    },

    calPlayerMagicFunc:function(target,param){
        var player = param.player;
        var playerData = param.data;
        var magic = Math.floor(playerData.maxMagic*(playerData.MagicRecovery/100));
        var realmagic  = _MFD.addMagic(player,magic);
        _GRM.addHitOnPlayerNode('lang',realmagic,this,player.isplayer,{ismsgmove:1});
        _MFN.refreshPlayerNode(this,player);
    },

    calPlayerDu:function(doactionPlayerNode,doactionPlayer,doactionPlayerData){
        return cc.callFunc(_FAM.calPlayerDuFunc,doactionPlayerNode,{player:doactionPlayer,data:doactionPlayerData});
    },

    calPlayerDuFunc:function(target,param){
        var player = param.player;
        var dublood = Math.floor(player.hp*_CS.duper);
        if(dublood>_CS.dumax){
            dublood=_CS.dumax;
        }
        _MFD.cutHp(player,dublood);
        _GRM.addHitOnPlayerNode('du',dublood,this,player.isplayer,{ismsgmove:1});
        _MFN.refreshPlayerNode(this,player);
    },

    //回合结束动作
    goon:function(){
        return  cc.callFunc(_FIGHT.energyGrow,_FIGHT);
    },

    //待机动作
    waitCmd:function(){
        return  cc.callFunc(_FIGHT.waitCmd,_FIGHT);
    },

    //逃跑成功动作
    runSuccess:function(){
        return  cc.callFunc(_FIGHT.runSuccess,_FIGHT);
    },

    onceAttack:function(param){
        var player = param.player;
        var target = param.target;
        var playerNode = _FIGHT.getPlayerNodeByPlayer(player);
        var targetNode = _FIGHT.getPlayerNodeByPlayer(target);
        var result = _MFD.getDamage(player,target,false,null);
        if(!result.isMiss){
            var realdamage = _MFD.cutHp(target,result.damage);
            if(!result.isSuper){
                _GRM.addHitOnPlayerNode(_CS.normalAni,realdamage,targetNode,target.isplayer,{ismsgmove:1});
            }else{
                _GRM.addHitOnPlayerNode(_CS.superAni,realdamage,targetNode,target.isplayer,{ismsgmove:1,msgcolor:_CS.bjcolor});
            }

            var playerData = _ROLEDATA.getRoleDataOfPlayer(player);
            var targetData = _ROLEDATA.getRoleDataOfPlayer(target);

            //判断吸血
            if(playerData.blood){
                var bloodData = Math.floor(-realdamage*playerData.blood/100);
                var realblood = _MFD.addHp(player,bloodData);
                _GRM.addHitOnPlayerNode('hong',realblood,playerNode,player.isplayer,{ismsgmove:1});
            }

            //判断反伤
            if(targetData.attackBack){
                var attackBackData = Math.floor(-realdamage*targetData.attackBack/100);
                _MFD.cutHp(player,attackBackData);
                //var realattackBack = _MFD.cut(player,attackBackData);
                //_GRM.addHitOnPlayerNode('xixue',realblood,playerNode,player.isplayer,{ismsgmove:1});
            }

            //判定反震
            if(targetData.hunSkin){
                RSH.addRealStatus(player.statusArr,'h1_2');
                _MFN.refreshPlayerInfo(playerNode,player);
            }

            //判断击晕
            var tempstunPer = playerData.stun-targetData.stunMiss;
            if(target.hp>0&&tempstunPer>0){
                if(tempstunPer>_CS.maxPer){
                    tempstunPer=_CS.maxPer;    
                }

                tempstunPer = _MFD.debuffPerUpdate(player,tempstunPer);

                if(
                    Math.random()<(tempstunPer/100)
                    &&targetData.clearBody<=0
                ){
                    RSH.addRealStatus(target.statusArr,'h1_1');
                }
            }

            //判断溅射
            if(playerData.jianshe){
                var targetArr = _FIGHT.getteamPlayerArrByPlayer(target,true);
                if(targetArr&&targetArr.length>0){
                    var jianshedamage = Math.floor(-realdamage*playerData.jianshe/100);
                    for(var i=0;i<targetArr.length;i++){
                        if(targetArr[i].hp>0){
                            var realjsdamage = _MFD.cutHp(targetArr[i],jianshedamage);
                            var jsnode = _FIGHT.getPlayerNodeByPlayer(targetArr[i]);
                            _GRM.addHitOnPlayerNode('putong',realjsdamage,jsnode,targetArr[i].isplayer,{ismsgmove:1});
                            _MFN.refreshPlayerNode(jsnode,targetArr[i]);
                        }
                    }
                }
            }

            //_MFN.refreshPlayerNode(playerNode,player);
            _MFN.refreshPlayerNode(targetNode,target);
        }else{
            _GRM.addHitOnPlayerNode(null,'miss',targetNode,target.isplayer,{ismsgmove:1});
        }
    },

    onceItem:function(param){

        //console.log('使用道具',param);

        var player = param.player;
        var playerNode = _FIGHT.getPlayerNodeByPlayer(player);
        var targetArr = param.targetArr;
        var itemName = param.itemName;
        var itemObj = _FIGHTITEM[itemName];
        var skilltype = itemObj.skilltype;
        var status = itemObj.status;
        var targeteg = itemObj.targeteg;

        //判断连发 lianfa
        if(_ROLEDATA.getRealAttr(player,"lianfa")&&Math.random()<_CS.lianfaPer){
            player.eg = 100;
        }

        if(player.isplayer&&_GAMEDATAHELPER.getFightItemNmb(itemName)<=0){
            _FIGHT.fightLogAdd('道具不足,使用失败...');
        }else if(itemObj.isZhaohuan){

            _FIGHT.fightLog(player.name+"使用"+itemName);

            if(player.isplayer)
                _CU.cutArrNmb(window.gameData.fightItem,itemName);

            if(window.fightData.playerTeam.length<5){
                if(window.gameData.catchMonster){
                    _FAM.onceZhaohuanAnimals(window.gameData.catchMonster);
                }else{
                    _FIGHT.fightLogAdd('没有可以召唤的野兽...');
                }
            }else{
                _FIGHT.fightLogAdd('没有位置召唤...');
            }

        }else {

            _FIGHT.fightLog(player.name+"使用"+itemName);

            if(player.isplayer)
                _CU.cutArrNmb(window.gameData.fightItem,itemName);

            _MFN.refreshPlayerInfo(playerNode,player);

            for(var i=0;i<targetArr.length;i++){

                var target = targetArr[i];

                var targetNode = _FIGHT.getPlayerNodeByPlayer(target);

                if(skilltype=="attack"){//输出系
                    if(target.hp>0){
                        var result = _MFD.getDamageOfItem(player,target,itemName);
                        if(
                            !result.isMiss
                            &&(
                                _ROLEDATA.getRealAttr(target,'anqimianyi')<=0
                                ||itemObj.atm
                            )
                        ){
                            _MFD.addEg(target,targeteg);
                            _FAM.addPlayerStatusArr(status,target);
                            var realdamage = _MFD.cutHp(target,result.damage);
                            _GRM.addHitOnPlayerNode(itemObj.ani,realdamage,targetNode,target.isplayer,{ismsgmove:1});
                            _MFN.refreshPlayerNode(targetNode,target);

                            if(target.hp<=0&&itemObj&&itemObj.isCatch&&_MFR.animalJob[target.job]){
                                window.gameData.catchMonster = target.name;
                                _FIGHT.fightLogAdd("捕获了:"+target.name);
                            }
                        }else{
                            _GRM.addHitOnPlayerNode(null,'miss',targetNode,target.isplayer,{ismsgmove:1});
                        }
                    }

                }else if(skilltype=="debuff"){//干扰系
                    if(target.hp>0){
                        if(_MFD.isHit(player,target,itemName)){

                            _MFD.addEg(target,targeteg);
                            _FAM.addPlayerStatusArr(status,target);
                            _GRM.addHitOnPlayerNode(itemObj.ani,'',targetNode,target.isplayer,null);
                            _MFN.refreshPlayerNode(targetNode,target);
                        }else{
                            _GRM.addHitOnPlayerNode(null,'miss',targetNode,target.isplayer,{ismsgmove:1});
                        }
                    }

                }else if(skilltype=="buff"){//恢复系

                    if(target.hp>0||itemObj.islive){

                        var result = _MFD.getHpAddOfItem(target,itemName);
                        var mgresult = _MFD.getMagicAddOfItem(target,itemName);

                        var realdamage = _MFD.addHp(target,result);
                        var mgresult = _MFD.addMagic(target,mgresult);

                        _MFD.addEg(target,targeteg);
                        _FAM.addPlayerStatusArr(status,target);

                        if(realdamage&&mgresult){
                            _GRM.addHitOnPlayerNode(itemObj.ani,realdamage+"\n"+mgresult,targetNode,target.isplayer,{ismsgmove:1});
                        }else if(realdamage){
                            _GRM.addHitOnPlayerNode(itemObj.ani,realdamage,targetNode,target.isplayer,{ismsgmove:1});
                        }else if(mgresult){
                            _GRM.addHitOnPlayerNode(itemObj.ani,mgresult,targetNode,target.isplayer,{ismsgmove:1,msgcolor:"#00F0FF"});
                        }else{
                            _GRM.addHitOnPlayerNode(itemObj.ani,null,targetNode,target.isplayer,{ismsgmove:1});
                        }
                        
                        //_GRM.addHitOnPlayerNode(itemObj.ani,realdamage,targetNode,target.isplayer,{ismsgmove:1});

                        if(_CU.isSamePlayer(target,player)){
                            _MFN.refreshPlayerInfo(targetNode,target);
                        }else{
                            _MFN.refreshPlayerNode(targetNode,target);
                        }

                    }
                }

            }

        }

    },

    //整容
    changeFace:function(param){
        if(param&&param.targetArr&&param.targetArr.length>0){
            var targetArr = param.targetArr;
            var target = targetArr[0];
            var pfobj = _PFM.getRandomPf();
            if(pfobj){
                target.pf = pfobj.pf;
                target.face = pfobj.face;
            }
        }
    },

    //掠夺
    onceLveduo:function(param){

        var targetArr = param.targetArr;
        var skillName = param.skillName;
        var skillObj = _SKILL[skillName];

        if(
            skillObj
            &&skillObj.getEquip
            &&window.fightData
            &&window.fightData.fightParam
            &&window.fightData.fightParam.type=='normalFight'
            &&targetArr.length>0
        ){
            var target = targetArr[0];
            if(target.equip){

                var randomArr = [];

                for(var key in target.equip){
                    if(target.equip[key])
                        randomArr.push(key);
                }

                if(randomArr.length>0){
                    var randomPos = _CU.randomObj(randomArr);
                    var randomEquip = target.equip[randomPos];
                    if(target.isplayer){
                        _GAMEDATAHELPER.pushItem(randomEquip);
                    }else{
                        if(_HDLVHELPER.getAttrByHdLv('lveduo')){
                            _GAMEDATAHELPER.pushItem(randomEquip);
                        }else{
                            _GAMEDATAHELPER.pushItem(_IOF.createObjByName(randomEquip.type,_MFR.randomEquipParam()));
                        }
                    }
                    target.equip[randomPos]=null;
                    _FIGHT.fightLogAdd("夺取了:"+randomEquip.type);
                }
            }
        }

    },

    onceZhaohuanAnimals:function(animal){
        if(_NPC[animal]){
            var playerFtype = window.fightData.playerTeam[0].ftype;
            var playerIndex = window.fightData.playerTeam.length;
            var playerLv = _EXPMANAGER.getLevelByExp(window.gameData.playerTeam[0].exp);
            var tempmonster = _ROF.createAnimal(animal,playerLv,{ftype:playerFtype});
            tempmonster.isCustomRole = true;
            tempmonster.isZhaohuan = true;
            tempmonster.teamIndex = playerIndex;
            tempmonster.isplayer = true;
            tempmonster.animals = null;
            tempmonster.historyAnimals={};
            tempmonster.statusArr = [];
            tempmonster.eg = 0;
            window.fightData.playerTeam.push(tempmonster);

            _FIGHT.initBeginStatus(tempmonster);
            /*
            if(_ROLEDATA.getRealAttr(tempmonster,'dun')){
				_FAM.addPlayerStatusArr(['dang_1'],tempmonster);
			}
            */

            var fnode = _MFN.createPlayerNode(tempmonster,true);
            fnode.setPosition(cc.v2(0,_FIGHT.ystart-playerIndex*_FIGHT.ylen));
            _FIGHT.playerLabel.addChild(fnode);
            _GRM.addHitOnPlayerNode('biansen',null,fnode,true,null);
            _FIGHT.playerNodeMap['player-'+playerIndex]=fnode;
        }
    },

    onceFenshen:function(param){
        var player = param.player;
        var isPlayer = player.isplayer;
        var mapPre = isPlayer?'player-':'army-';
        var sourceArrKey = isPlayer?'playerTeam':'armyTeam';
        //var sourceArmyKey = !isPlayer?'playerTeam':'armyTeam';
        var sourceArr =  window.fightData[sourceArrKey];

        if(sourceArr.length<5){

            var newplayer = _CU.cloneObj(player);
            newplayer.teamIndex = sourceArr.length;
            newplayer.isCustomRole = true;
            newplayer.isZhaohuan = true;
            newplayer.isMainRole = 0;
            sourceArr.push(newplayer);

            var fnode = _MFN.createPlayerNode(newplayer,isPlayer);
            fnode.setPosition(cc.v2(0,_FIGHT.ystart-newplayer.teamIndex*_FIGHT.ylen));
            _GRM.addHitOnPlayerNode('biansen',null,fnode,false,null);
            if(isPlayer){
                _FIGHT.playerLabel.addChild(fnode);
            }else{
                _FIGHT.armyLabel.addChild(fnode);
            }
            _FIGHT.playerNodeMap[mapPre+newplayer.teamIndex]=fnode;

        }else{
            _FIGHT.fightLogAdd('人数过多分身失败');
        }

    },

    onceZhanhuan:function(param){

        var player = param.player;
        var skillName = param.skillName;
        var skillObj = _SKILL[skillName];
        var isPlayer = player.isplayer;
        var playerIndex = player.teamIndex;
        var mapPre = isPlayer?'player-':'army-';
        var sourceArrKey = isPlayer?'playerTeam':'armyTeam';
        var sourceArmyKey = !isPlayer?'playerTeam':'armyTeam';
        var arr = skillObj.arr;

        //移除当前友军对象
        for(var i=0;i<window.fightData[sourceArrKey].length;i++){
            if(i!=playerIndex){
                var tmpPlayerNode = _FIGHT.playerNodeMap[mapPre+i];
                _FIGHT.playerNodeMap[mapPre+i]=null;
                _GRM.putNode(tmpPlayerNode);
            }
        }
        window.fightData[sourceArrKey]=[window.fightData[sourceArrKey][playerIndex]];

        //创建召唤对象
        if(arr){
            for(var i=0;i<arr.length;i++){
                window.fightData[sourceArrKey].push(_ROF.createRoleAndSetPlayerLv(arr[i]));
            }
        }else{
            for(var i=0;i<4;i++){
                if(window.fightData[sourceArmyKey][i]){
                    window.fightData[sourceArrKey].push(_CU.cloneObj(window.fightData[sourceArmyKey][i]));
                }
            }
        }

        //console.log('重构队伍:',window.fightData[sourceArrKey]);

        //重新创建形象
        for(var i=0;i<window.fightData[sourceArrKey].length;i++){
            if(i!=0){
                var tmplayer = window.fightData[sourceArrKey][i];
                tmplayer.teamIndex = i;
                tmplayer.isplayer = isPlayer;
                tmplayer.animals = null;
                tmplayer.historyAnimals={};
                if(i!=0){
                    tmplayer.statusArr = [];
                }
                if(arr==null){
                    _ROF.recreateObjByHdlv(tmplayer);
                }

                tmplayer.eg = 0;

                /*
                tmplayer.eg = _ROLEDATA.getRealAttr(tmplayer,'beginEnergy');
                if(_ROLEDATA.getRealAttr(tmplayer,'dun')){
                    _FAM.addPlayerStatusArr(['dang_1'],tmplayer);
                }
                */

                _FIGHT.initBeginStatus(tmplayer);

                var fnode = _MFN.createPlayerNode(tmplayer,isPlayer);
                fnode.setPosition(cc.v2(0,_FIGHT.ystart-i*_FIGHT.ylen));
                _GRM.addHitOnPlayerNode('biansen',null,fnode,false,null);
                if(isPlayer){
                    _FIGHT.playerLabel.addChild(fnode);
                }else{
                    _FIGHT.armyLabel.addChild(fnode);
                }
                _FIGHT.playerNodeMap[mapPre+i]=fnode;
                _FIGHT.ifActive(tmplayer,fnode);
            }
        }

    },

    getEnabelItem:function(player){

        if(player.isplayer){

            for(var i=0;i<window.gameData.fightItem.length;i++){
                if(
                    _FIGHTITEM[window.gameData.fightItem[i].type]
                    &&_FIGHTITEM[window.gameData.fightItem[i].type].skilltype=="attack"
                    ){
                    return window.gameData.fightItem[i].type;
                }
            }

        }else{

            var playerLv = player.exp?_EXPMANAGER.getLevelByExp(player.exp):player.lv;

            if(playerLv>=800){
                return "飞剑";
            }else if(playerLv>=600){
                return "金钱镖";
            }else if(playerLv>=400){
                return "飞蝗石";
            }else if(playerLv>=200){
                return "毒镖";
            }else{
                return "飞刀";
            }

        }

        return null;

    },

    onceSkill:function(param){
        var player = param.player;
        var playerNode = _FIGHT.getPlayerNodeByPlayer(player);
        var targetArr = param.targetArr;
        var skillName = param.skillName;
        var skillObj = _SKILL[skillName];
        var skilltype = skillObj.skilltype;
        var selfeg = skillObj.selfeg;
        var selfStatus = skillObj.selfstatus;
        var status = skillObj.status;
        var targeteg = skillObj.targeteg;

        if(skillObj.cut>player.mg){
            //console.log('魔法不足',skillObj.cut,player.mg);
            _FIGHT.fightLogAdd('魔法值不足,技能释放失败...');

        }else if(skilltype=="bianhua"){//变鸡术

            _FIGHT.fightLog(player.name+"使用"+skillName);

            player.mg-=skillObj.cut;

            window.gameData.catchMonster = skillObj.animals;

            for(var i=0;i<targetArr.length;i++){
                var target = targetArr[i];
                var targetNode = _FIGHT.getPlayerNodeByPlayer(target);
                _FAM.doConceAnimals(skillObj,target,targetNode);
                _MFN.refreshPlayerNode(targetNode,target);
                _GRM.addHitOnPlayerNode(skillObj.ani,null,targetNode,target.isplayer,{ismsgmove:1});
            }

        }else if(skilltype=="goldattack"){

            _FIGHT.fightLog(player.name+"使用"+skillName);
            var golddamage = 100000000;
            if(player.isplayer){

                if(window.gameData.gold>=100000000){
                    window.gameData.gold-=100000000;
                }else{
                    golddamage = window.gameData.gold;
                    window.gameData.gold=0;
                }

            }

            for(var i=0;i<targetArr.length;i++){

                var target = targetArr[i];
                var targetNode = _FIGHT.getPlayerNodeByPlayer(target);
                var targetData = _ROLEDATA.getRoleDataOfPlayer(target);

                if(_MFD.isHit(player,target,skillName)&&targetData.anqimianyi<=0){

                    var realdamage = _MFD.cutHp(target,golddamage);
                    
                    _GRM.addHitOnPlayerNode(skillObj.ani,realdamage,targetNode,target.isplayer,{ismsgmove:1});
                    
                    _MFN.refreshPlayerNode(targetNode,target);

                }else{

                    _GRM.addHitOnPlayerNode(null,'miss',targetNode,target.isplayer,{ismsgmove:1});

                }

            }


        }else if(skilltype=="baozha"){//自爆

            _FIGHT.fightLog(player.name+"使用"+skillName);

            player.mg-=skillObj.cut;

            var cutplayerhp = player.hp-1;

            player.hp=1;

            _GRM.addHitOnPlayerNode(skillObj.ani,cutplayerhp,playerNode,player.isplayer,{ismsgmove:1});

            _MFN.refreshPlayerInfo(playerNode,player);

            for(var i=0;i<targetArr.length;i++){

                var target = targetArr[i];
                var targetNode = _FIGHT.getPlayerNodeByPlayer(target);
                var targetData = _ROLEDATA.getRoleDataOfPlayer(target);

                //if(_MFD.isHit(player,target,skillName)){
                if(Math.random()<skillObj.per){

                    var realdamage = _MFD.cutHp(target,cutplayerhp);
                    
                    _GRM.addHitOnPlayerNode(skillObj.ani,realdamage,targetNode,target.isplayer,{ismsgmove:1});
                    
                    _MFN.refreshPlayerNode(targetNode,target);

                }else{

                    _GRM.addHitOnPlayerNode(null,'miss',targetNode,target.isplayer,{ismsgmove:1});

                }

            }

        }else if(skilltype=="anqi"){

            var enableItem = _FAM.getEnabelItem(player);
            if(enableItem){
                //console.log('使用道具:',enableItem);
                param.itemName = enableItem;
                _FAM.onceItem(param);
            }else{
                _FIGHT.fightLogAdd('道具不足,技能释放失败...');
            }

        }else if(skilltype=='fenshen'){

            _FIGHT.fightLog(player.name+"使用"+skillName);

            player.mg-=skillObj.cut;

            _MFN.refreshPlayerInfo(playerNode,player);

            _FAM.onceFenshen(param);

        }else if(skilltype=='zhaohuan'){//召唤系技能

            _FIGHT.fightLog(player.name+"使用"+skillName);

            player.mg-=skillObj.cut;

            player.eg = -100;

            _MFN.refreshPlayerInfo(playerNode,player);

            _FAM.onceZhanhuan(param);

        }else {

            _FIGHT.fightLog(player.name+"使用"+skillName);

            player.mg-=skillObj.cut;

            if(selfeg&&Math.random()<0.45){
                if(player.eg+selfeg>100){
                    player.eg=100;
                }else{
                    player.eg+=selfeg;
                }
            }

            if(selfStatus){
                //var selfclearbody = _ROLEDATA.getRealAttr(player,'clearBody');
                //for(var i=0;i<selfStatus.length;i++){
                //    if(!selfclearbody||selfclearbody<=0)
                //        RSH.addRealStatus(player.statusArr,selfStatus[i]);
                //}
                _FAM.addPlayerStatusArr(selfStatus,player);
            }

            _FAM.doConceAnimals(skillObj,player,playerNode);

            _MFN.refreshPlayerInfo(playerNode,player);

            for(var i=0;i<targetArr.length;i++){

                var target = targetArr[i];
                var targetNode = _FIGHT.getPlayerNodeByPlayer(target);
                var targetData = _ROLEDATA.getRoleDataOfPlayer(target);

                if(skilltype=="attack"){//输出系
                    if(target.hp>0){
                        var result = _MFD.getDamageOfSkill(player,target,skillName);
                        if(
							!result.isMiss
							&&(//如果技能不是100%命中则计算命中
								!skillObj.per
								||Math.random()<skillObj.per
							)
						){
                            _MFD.addEg(target,targeteg);
                            _FAM.addPlayerStatusArr(status,target);

                            var realdamage = _MFD.cutHp(target,result.damage);

                            //慈悲刀
                            if(skillObj.nodie&&target.hp<=0){
                                target.hp=1;
                            }

                            if(skillObj.changeFace){
                                _FAM.changeFace(param);
                                _MFN.switchAni(targetNode,target.pf);
                            }

                            //_GRM.addHitOnPlayerNode(skillObj.ani,realdamage,targetNode,target.isplayer,{ismsgmove:1});
                            //判断是否暴击
                            if(!result.isSuper){
                                _GRM.addHitOnPlayerNode(skillObj.ani,realdamage,targetNode,target.isplayer,{ismsgmove:1});
                            }else{
                                _GRM.addHitOnPlayerNode(skillObj.ani,realdamage,targetNode,target.isplayer,{ismsgmove:1,msgcolor:_CS.bjcolor});
                            }
                            _MFN.refreshPlayerNode(targetNode,target);

                            //判断反伤
                            if(targetData.attackBack&&!skillObj.ismagic){
                                var attackBackData = Math.floor(-realdamage*targetData.attackBack/100);
                                _MFD.cutHp(player,attackBackData);
                                _MFN.refreshPlayerInfo(playerNode,player);
                            }

                            //判断法术反伤
                            if(targetData.mattackBack&&skillObj.ismagic){
                                var attackBackData = Math.floor(-realdamage*targetData.attackBack/100);
                                _MFD.cutHp(player,attackBackData);
                                _MFN.refreshPlayerInfo(playerNode,player);
                            }

                            _FAM.onceLveduo(param);

                        }else{
                            _GRM.addHitOnPlayerNode(null,'miss',targetNode,target.isplayer,{ismsgmove:1});
                        }
                    }
                }else if(skilltype=="debuff"){//干扰系
                    if(target.hp>0){
                        if(_MFD.isHit(player,target,skillName)){

                            var mgresult = _MFD.getMagicAddOfSkill(player,skillName);
                            var mgresult = _MFD.addMagic(target,mgresult);

                            _MFD.addEg(target,targeteg);
                            _FAM.addPlayerStatusArr(status,target);
                            _GRM.addHitOnPlayerNode(skillObj.ani,'',targetNode,target.isplayer,null);
                            _MFN.refreshPlayerNode(targetNode,target);
                        }else{
                            _GRM.addHitOnPlayerNode(skillObj.ani,'miss',targetNode,target.isplayer,{ismsgmove:1});
                        }
                    }

                }else if(skilltype=="buff"){//恢复系

                    if(target.hp>0||skillObj.islive){

                        var result = _MFD.getHpAddOfSkill(player,skillName);
                        var mgresult = _MFD.getMagicAddOfSkill(player,skillName);
                        _MFD.addEg(target,targeteg);
                        _FAM.addPlayerStatusArr(status,target);

                        var realdamage = _MFD.addHp(target,result);
                        var mgresult = _MFD.addMagic(target,mgresult);
                        
                        if(realdamage&&mgresult){
                            _GRM.addHitOnPlayerNode(skillObj.ani,realdamage+"\n"+mgresult,targetNode,target.isplayer,{ismsgmove:1});
                        }else if(realdamage){
                            _GRM.addHitOnPlayerNode(skillObj.ani,realdamage,targetNode,target.isplayer,{ismsgmove:1});
                        }else if(mgresult){
                            _GRM.addHitOnPlayerNode(skillObj.ani,mgresult,targetNode,target.isplayer,{ismsgmove:1,msgcolor:"#00F0FF"});
                        }else{
                            _GRM.addHitOnPlayerNode(skillObj.ani,null,targetNode,target.isplayer,{ismsgmove:1});
                        }
                        

                        if(_CU.isSamePlayer(target,player)){
                            _MFN.refreshPlayerInfo(targetNode,target);
                        }else{
                            _MFN.refreshPlayerNode(targetNode,target);
                        }
                    }
                }

            }

        }

    },

    //变身
    doConceAnimals:function(skillObj,player,playerNode){

        //console.log('变身:',skillObj);

        if(player.animals=='咕咕鸡')
            return;

        if(skillObj.animals&&_ANIMALS[skillObj.animals]){
            var animalsConf = _ANIMALS[skillObj.animals];
            _MFN.switchAni(playerNode,animalsConf.pf);

            //var oldplayerData = _ROLEDATA.getRoleDataOfPlayer(player);
            player.animals = skillObj.animals;
            player.historyAnimals[skillObj.animals]=1;
            var newplayerData = _ROLEDATA.getRoleDataOfPlayer(player);
            player.hp = newplayerData.maxHp;
            player.mg = newplayerData.maxMagic;

        }

    },

    doOnceActionFunc:function(targetMethod,param){
        var player = param.player;
        var type = param.type;
        var actionName = _FAM.ATYPE_LABEL_MAP[type];

        var playerRole = this.getChildByName('role');
        playerRole.getComponent(cc.Animation).play('attack');
        if(actionName){
            _GRM.addHitOnPlayerNode(null,actionName,this,player.isplayer,null);
        }

        if(//普通攻击动作
            type==_FAM.ATYPE_ATTACK
            ||type==_FAM.ATYPE_ATTACK2
            ||type==_FAM.ATYPE_ATTACK3
            ||type==_FAM.ATYPE_ATTACK4
        ){
            _FAM.onceAttack(param);

        }else if(//技能动作
            type==_FAM.ATYPE_SKILL
            ||type==_FAM.ATYPE_SKILL2
            ||type==_FAM.ATYPE_SKILL3
            ||type==_FAM.ATYPE_SKILL4
        ){
            
            _FAM.onceSkill(param);

        }else if(type==_FAM.ATYPE_ITEM){
            _FAM.onceItem(param);
        }
    },

    addPlayerStatusArr:function(status,player){
        
        var hasclearBody = _ROLEDATA.getRealAttr(player,'clearBody');

        if(status&&player&&(!hasclearBody||hasclearBody<=0)){

            //console.log('附加状态:',status,player);

            for(var j=0;j<status.length;j++){
                RSH.addRealStatus(player.statusArr,status[j]);
            }

            //console.log('附加状态后:',player);

        }else{

            //console.log('无法附加状态:',status,player,hasclearBody);

        }

    }

}